﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.


using NSQL.Expressions;
using NSQL.Sharpen;

namespace NSQL
{
    public enum JoinType : byte
    {
        Inner = 0,
        Left = 1,
        Right = 2,
        LeftOuter = 3,
        RightOuter = 4,
        FullJoin = 5,
        CrossJoin = 6
    }

    public interface IJoinNode : ITableOrSubquery, IJoinable
    {
        JoinType Type { get;  }
        IJoinable Base { get;  }
        IJoinable JoinTable { get;  }
        IPredicateExpression Condition { get; }
    }

    public class JoinNode : IJoinNode
    {
        public JoinType Type { get;  }
        public IJoinable Base { get;  }
        public IJoinable JoinTable { get;  }
        public IPredicateExpression Condition { get; }

        public JoinNode(IJoinable @base, IJoinable joinTable, JoinType joinType, IPredicateExpression condition)
        {
            Base = @base;
            JoinTable = joinTable;
            Type = joinType;
            Condition = condition;
        }

        object IDeepClone.DeepCopy()
        {
            return new JoinNode(Base, JoinTable, Type, Condition.DeepClone());
        }

        public Identifier Alias { get; set; }
        public object Tag { get; set; }
    }
}